<?php

namespace Wap\Action;

/**
 * ============================================================================
 * MXCMall开源商城
 * 官网地址:http://www.mothink.cn
 * 联系QQ:510858687
 * ============================================================================
 */
class PayAction extends BaseAction {

    public function index() {
        redirect(U('Users/login'));
    }


    public function todo() {

    	die("test");
    }

    public function allOrderList() {
        $m = M('orders');
        $num = 999999;
        $page = I('page') ? I('page') : 1;
        $current = $page;
        $page = ($page - 1) * $num;

        $order['count'] = $m->where('orderFlag = 1 AND userId=' . $userId)->count();
        $order['num'] = $num;
        $order['current'] = $current;
        $order['sumpage'] = ceil($order['count'] / $num);

        $orderList = M('orders')->where('payType = 1 and orderFlag = 1 ')->field('orderId,orderNo,totalMoney,postage,supPrice,supPostage,payType,buyway,orderStatus')->order('orderId DESC')->limit($page, $num)->select();
        if (empty($orderList))
            return;

        $data = array();
        foreach ($orderList as $k=>$v) {
            $v['goods'] = M('order_goods')->where('orderId=' . $v['orderId'])->select();
            foreach ( $v['goods'] as $key2 => &$value2) {
            	$value2['parentId'] = M("goods")->where("goodsId=".$value2['goodsId'])->getField('parentId');

            }

            $data[] = $v;

            $userId_B[$k1]['userId'] = M("shops")->where("shopId={$goodsData['shopId']}")->getField('userId');
           $parentId = $goodsData['parentId']?$goodsData['parentId']:0 ;
           $tmp_goods = M("goods")->where("goodsId={$parentId}")->find();
           //
           $userId_A[$k1]['goodsId'] = $tmp_goods['goodsId'];
           $userId_A[$k1]['shopId'] = $tmp_goods['shopId'];
           $userId_A[$k1]['shopPrice'] = $tmp_goods['shopPrice'];
           $userId_A[$k1]['userId'] = M("shops")->where("shopId={$userId_A[$k1]['shopId']}")->getField('userId');

           $userId_B[$k1]['price'] =  $goodsData['shopPrice'] - $userId_A[$k1]['shopPrice']  ;

        }
        $order['order'] = $data;
prt($order);
        return $order;
    }


}